//
//  ScanToturialView.m
//  Unity-iPhone
//
//  Created by Karl on 2017/3/29.
//
//

#import "ScanToturialView.h"

@implementation ScanToturialView{
    UIView *_bg;
    UIImageView *_toturialBg;
    UIImageView *_text;
    UIImageView *_example;
    UIButton *_closeBtn;
}

- (instancetype)init{
    self = [super init];
    if (self) {
        _bg = [UIView new];
        [_bg setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.6]];
        [self addSubview:_bg];
        
        _toturialBg = [UIImageView new];
        [_toturialBg setImage:kImgFromFile(@"scan_pop_bg", @"png")];
        [self addSubview:_toturialBg];
        
        _text = [UIImageView new];
        [_text setImage:kImgFromFile(Babel(@"scan_pop_text"), @"png")];
        [_toturialBg addSubview:_text];
        
        _example = [UIImageView new];
        [_example setImage:kImgFromFile(@"scan_pop_image", @"png")];
        [_toturialBg addSubview:_example];
        
        _closeBtn = [UIButton new];
        [_closeBtn addTarget:self action:@selector(closeToturail:) forControlEvents:UIControlEventTouchUpInside];
        [_closeBtn setBackgroundImage:[UIImage imageNamed:@"all_close"] forState:UIControlStateNormal];
        [self addSubview:_closeBtn];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat scale = 1.0;
    if (isPad) {
        scale = SizeScaleX;
    }else{
        scale = SizeScaleY;
    }
    
    _bg.left = 0;
    _bg.top = 0;
    _bg.width = self.width;
    _bg.height  =self.height;
    
    _toturialBg.centerY = self.height/2;
    _toturialBg.left = 100 * scale;
    _toturialBg.width = self.width - _toturialBg.left * 2;
    _toturialBg.height = 390 * scale;
    
    _text.top = 51 * scale;
    _text.left = 28 * scale;
    _text.width = _toturialBg.width - _text.left * 2;
    _text.height = 119.3 * scale;
    
    _example.top = _text.bottom + 20 * scale;
    _example.centerX = _toturialBg.width/2;
    _example.width = 251.3*scale;
    _example.height = 152.3*scale;
    
    _closeBtn.width = 30;
    _closeBtn.height = 30;
    _closeBtn.top = _toturialBg.top + 6.7;
    _closeBtn.right = _toturialBg.right - 6.7;
    
}

- (void)closeToturail:(id)sender{
    self.hidden = YES;
}
@end
